
import { UserService } from './../user/user.service';
import { PrismaService } from 'src/prisma/prisma.service';
import { Controller, Get, Post, Body, Patch, Param, Delete, NotFoundException, Headers, Ip } from '@nestjs/common';
import { AuthService } from './auth.service';
import { CreateAuthDto } from './dto/create-auth.dto';
import { UpdateAuthDto } from './dto/update-auth.dto';
import { ApiOperation } from '@nestjs/swagger';
import { LoginToken } from './models/auth.model';
import { LoginDto } from './dto/auth.dto';
@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService,) { }

  @Post()
  create(@Body() createAuthDto: CreateAuthDto) {
    return this.authService.create(createAuthDto);
  }

  @Post('login')
  @ApiOperation({ summary: '登录' })
  async login(@Body() dto: LoginDto, @Ip() ip: string, @Headers('user-agent') ua: string): Promise<LoginToken> {
    // 暂时去掉验证码
    // await this.captchaService.checkImgCaptcha(dto.captchaId, dto.verifyCode)
    return await this.authService.login(
      dto.username,
      dto.password,
      ip,
      ua,
    )

  }

  @Post('register')
  @ApiOperation({ summary: '注册' })
  async registered(@Body() dto: LoginDto) {
    return await this.authService.register(dto)
  }

  @Get()
  findAll() {
    return this.authService.findAll();
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.authService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateAuthDto: UpdateAuthDto) {
    return this.authService.update(+id, updateAuthDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.authService.remove(+id);
  }

}
